import axios from 'axios'
const url = 'http://localhost:4000'
const http = axios.create({
    baseURL: url,
    timeout: 5000,
    // headers:{
    //     token:localStorage.getItem('TOKEN')
    // }
})

const get = (url: string, data = {}) => {
    return http.get(
        `${url}`,
        {
            params: data,
            headers: {
                token: localStorage.getItem("TOKEN")
            }
        }
    )
        .then(response => response.data)
}
const post = (url: string, data = {}) => {
    return http.post(
        `${url}`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                token: localStorage.getItem("TOKEN")
            }
        }
    )
        .then(response => response.data)
}
const upload = (url: string, data = {}) => {
    return http.post(
        `${url}`,
        data,
        {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: localStorage.getItem('TOKEN')
            }
        }
    )
        .then(response => response.data)
}

export default {
    url: 'http://localhost:4000',
    get,
    post,
    upload
}